package elevatronic.view.right.brain;

import javax.swing.JLabel;

import elevatronic.Elevatronic;
import elevatronic.view.MPanel;

public class BrainPanel extends MPanel{
	private static final long serialVersionUID = 5789304257808010250L;

	//count of cycle elapsed since the start of the app
	private int elapsedCycle;
	public int getElapsedCycle() {
		return elapsedCycle;
	}
	public void setElapsedCycle(int elapsedCycle) {
		this.elapsedCycle = elapsedCycle;
	}
	

	//label title of elapsed cycle count
	private JLabel elapsedCycleLabel;
	public JLabel getElapsedCycleLabel() {
		if (elapsedCycleLabel==null){
			elapsedCycleLabel=new JLabel();
		}
		return elapsedCycleLabel;
	}
	public void setElapsedCycleLabel(JLabel elapsedCycleLabel) {
		this.elapsedCycleLabel = elapsedCycleLabel;
	}
	
	//label value of elapsed cycle count
	private JLabel elapsedCycleTitleLabel;
	public JLabel getElapsedCycleTitleLabel() {
		if (elapsedCycleTitleLabel==null){
			elapsedCycleTitleLabel=new JLabel("Elapsed cycle label : ");
		}
		return elapsedCycleTitleLabel;
	}
	public void setElapsedCycleTitleLabel(JLabel elapsedCycleTitleLabel) {
		this.elapsedCycleTitleLabel = elapsedCycleTitleLabel;
	}

	//shortcut of average waiting time of people
	public int getAverageWaitingTime(){
		return Elevatronic.getSingleton().getBuilding().getAverageWaitingTime();
	}
	
	
	//label value of average waiting time of people
	private JLabel averageWaitingTimeLabel;
	public JLabel getAverageWaitingTimeLabel() {
		if (averageWaitingTimeLabel==null){
			averageWaitingTimeLabel=new JLabel();
		}
		return averageWaitingTimeLabel;
	}
	public void setAverageWaitingTimeLabel(JLabel averageWaitingTimeLabel) {
		this.averageWaitingTimeLabel = averageWaitingTimeLabel;
	}	
	
	//label title of average waiting time of people
	private JLabel averageWaitingTimeTitleLabel;
	public JLabel getAverageWaitingTimeTitleLabel() {
		if (averageWaitingTimeTitleLabel==null){
			averageWaitingTimeTitleLabel=new JLabel("Average waiting time : ");
		}
		return averageWaitingTimeTitleLabel;
	}
	public void setAverageWaitingTimeTitleLabel(JLabel averageWaitingTimeTitleLabel) {
		this.averageWaitingTimeTitleLabel = averageWaitingTimeTitleLabel;
	}
	

	/**
	 * Constructor
	 * @param wdth width of the panel
	 * @param hght height of the panel
	 */
	public BrainPanel(int wdth, int hght) {
		super(wdth, hght);
		getElapsedCycleTitleLabel().setBounds(5, 20,200,30);
		getElapsedCycleLabel().setBounds(20, 40,200,30);
		
		getAverageWaitingTimeTitleLabel().setBounds(5, 80,200,30);
		getAverageWaitingTimeLabel().setBounds(20, 100,200,30);
		
		add(getElapsedCycleLabel());
		add(getElapsedCycleTitleLabel());
		
		add(getAverageWaitingTimeLabel());
		add(getAverageWaitingTimeTitleLabel());
	}
	
	//iteration of the brain panel
	public void update(int step){
		super.update(step);
		elapsedCycle++;
		getElapsedCycleLabel().setText(String.valueOf(elapsedCycle));		
		getAverageWaitingTimeLabel().setText(String.valueOf(getAverageWaitingTime()));
	}
}
